package com.xuecheng.content.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xuecheng.api.content.model.dto.TeachplanMediaDTO;
import com.xuecheng.common.domain.response.RestResponse;
import com.xuecheng.common.exception.ExceptionCast;
import com.xuecheng.content.common.constant.ContentErrorCode;
import com.xuecheng.content.convert.TeachplanMediaConvert;
import com.xuecheng.content.entity.TeachplanMedia;
import com.xuecheng.content.mapper.TeachplanMediaMapper;
import com.xuecheng.content.service.TeachplanMediaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 黄子弟
 */
@Slf4j
@Service
public class TeachplanMediaServiceImpl extends ServiceImpl<TeachplanMediaMapper, TeachplanMedia> implements TeachplanMediaService {

    @Override
    public RestResponse<TeachplanMediaDTO> getById(Long mediaId) {
        if (ObjectUtils.isEmpty(mediaId)) {
            ExceptionCast.cast(ContentErrorCode.E_120023);
        }

        LambdaQueryWrapper<TeachplanMedia> wrapper = Wrappers.lambdaQuery(TeachplanMedia.class);
        wrapper.eq(TeachplanMedia::getMediaId, mediaId);
        TeachplanMedia teachplanMedia = this.getOne(wrapper);

        TeachplanMediaDTO teachplanMediaDTO = TeachplanMediaConvert.INSTANCE.po2dto(teachplanMedia);

        RestResponse<TeachplanMediaDTO> response = new RestResponse<>();
        response.setResult(teachplanMediaDTO);

        return response;



    }
}
